package com.example.demo.javatest.thread.tongxin;

/**
 * Created by liujiahao on 2019/3/13.
 */
public class DbTools {
    private boolean preIsA=false;
    synchronized public void insertA(){
        while (preIsA){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        for (int i = 0; i <5 ; i++) {
            System.out.println("往a数据库添加");
        }
        preIsA=true;
        notifyAll();
    }
    synchronized public void insertB(){
        while (preIsA==false){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        for (int i = 0; i < 5; i++) {

            System.out.println("往b数据库里添加");
        }
        preIsA=false;
        notifyAll();
    }
}
